package com.neusoft.a312cxy.android18cxy.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.a312cxy.android18cxy.Listener.PostListener;
import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.adapter.ShaiTuInfoAdapter;
import com.neusoft.a312cxy.android18cxy.bean.ShaiTuInfo;
import com.neusoft.a312cxy.android18cxy.model.ShaiTuModel;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Young on 2017/10/16.
 */

public class ShaiTuInfoActivity extends AppCompatActivity {
    SharedPreferences sid;

    private TextView user_name;
    private TextView introduction;
    private TextView update_time;
   // private List<ClubInfo> list;
     private RecyclerView recyclerView;
    private ImageView thumb ,photo;
    private Button replyBtn;
    // private VideoView videoView;
    private List<ShaiTuInfo> ShaiTu;
    //  private Context mContext;
    private String shaitu_id,user_id;
private List mDatelist;
    String userid;
    private EditText edt;
String reply_userid;
    String reply ,photo1;
    public ShaiTuInfoActivity() {
    }
    // private List<ClubInfo> mDataList;
    // private  String R_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shaitu_info);
        initView();
        saveDate();
        GetShaiTuInfo();

        reply_userid="2";
      //  getShaiTureply();




    }

   public void initView(){
       //user_name=(TextView)findViewById(R.id.user_name);
       // introduction=(TextView)findViewById(R.id.introduction) ;
     //   update_time=(TextView)findViewById(R.id.update_time);
       // thumb=(ImageView)findViewById(R.id.thumb);
        //   videoView=(VideoView)findViewById(R.id.videoView);
       edt=(EditText)findViewById(R.id.edtpush);
       recyclerView = (RecyclerView)findViewById(R.id.ss);
       recyclerView.setLayoutManager(new LinearLayoutManager(ShaiTuInfoActivity.this));
       recyclerView.setItemAnimator(new DefaultItemAnimator());
       photo=(ImageView)findViewById(R.id.photoaaa) ;
       replyBtn=(Button)findViewById(R.id.reply1);
       replyBtn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {

               ShaiTuModel shaiTuModel = new ShaiTuModel();
               shaiTuModel.upcomment(shaitu_id,userid,reply_userid,edt.getText().toString(),postcomemnt );
             //  edt.getText().toString().trim()
           }


       });

    }

    public void saveDate(){
        Intent intent = getIntent();
        Bundle  bundle =  intent.getExtras();
        photo1=intent.getStringExtra("photo");
            if(photo1!=null){
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+photo1).into(photo);
        }
        else {
            photo.setImageResource(R.drawable.i5);
        }
        shaitu_id = bundle.getString("shaitu_id");
        userid = bundle.getString("userid");
        //  sid=getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        //   user_id=sid.getString("user_id", "");
    }


    public void GetShaiTuInfo(){
        final ShaiTuModel ShaiTuModel=new ShaiTuModel();
        Call<List<ShaiTuInfo>> call=ShaiTuModel.getShaiTuInfo(shaitu_id);
        call.enqueue(new Callback<List<ShaiTuInfo>>() {
            @Override
            public void onResponse(Call<List<ShaiTuInfo>> call, Response<List<ShaiTuInfo>> response) {
                mDatelist=response.body();

             ShaiTuInfoAdapter adapter= new ShaiTuInfoAdapter(ShaiTuInfoActivity.this,mDatelist);



                recyclerView.setAdapter(adapter);  }
//                if(!ShaiTu.getPhoto().isEmpty())
//                {
//                    Picasso.with(ShaiTuInfoActivity.this).load("http://172.24.10.175/workout/Uploads/"+ShaiTu.getPhoto()).into(thumb);
//                }
/*              else
                {
                    ClubInfoActivity.clubthumb.setImageResource(R.drawable.ic_club);
                }*/

/*                if(!Club.getClubthumb().isEmpty())
                {
                    Picasso.with(ClubInfoActivity.this).load("http://172.24.10.175/workout/Uploads/"+Club.getClubthumb()).into(clubthumb);
                }*/
/*                else{
                   ImageView.clubthumb.setImageResource(R.drawable.ic_club);
                }*/
                //user_name.setText(ShaiTu.);
              //  introduction.setText(ShaiTu.getIntroduction());
               // update_time.setText(ShaiTu.getUpdate_time());


            /*            @Override
                        public void onResponse(Call<List<ClubInfo>> call, Response<List<ClubInfo>> response) {
                            List<ClubInfo> data=response.body();
                            recyclerView.setAdapter(new ClubcourseAdapter(ClubInfoActivity.this,data));
                        }*/
            @Override
            public void onFailure(Call<List<ShaiTuInfo>> call, Throwable t) {

            }
        });

    }/*
    public void upreply(String shaitu_id,String userid,String 	reply_userid final PostListener postListener){
        @Override
                public void onResponse (String)

    }
*/PostListener<String> postcomemnt=new PostListener<String>() {
        @Override
        public void onResponse(String post) {
            if (post.equals("0")){
                Toast.makeText(ShaiTuInfoActivity.this, "发布失败", Toast.LENGTH_SHORT).show();

            }else {
                Toast.makeText(ShaiTuInfoActivity.this, "发布成功", Toast.LENGTH_SHORT).show();
                GetShaiTuInfo();
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };

 /*   public void getShaiTureply(){

        ShaiTuModel ShaiTuModel=new ShaiTuModel();
        Call <ShaiTuInfo> call=ShaiTuModel.getShaiTuInfo(id);
        call.enqueue(new Callback <ShaiTuInfo>() {
            @Override
            public void onResponse(Call<ShaiTuInfo> call, Response<ShaiTuInfo> response) {
                List<ShaiTuInfo> data = response.body().getId();
                //  System.out.println("9");
                recyclerView.setAdapter(new ShaiTuInfoAdapter(ShaiTuInfoActivity.this, data));

            }

            @Override
            public void onFailure(Call<ShaiTuInfo> call, Throwable t) {

                //  System.out.println("8");
            }
        });


    }


*/

}